/*
DigitalFlipbook Source Code License Agreement
Copyright(c) 2008 DigitalFlipbook. All rights reserved.
	
Please read this Source Code License Agreement carefully before using
the source code.
	
DigitalFlipbook grants to you a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable copyright license, to reproduce,
prepare derivative works of, publicly display, publicly perform, and
distribute this source code and such derivative works in source or
object code form without any attribution requirements.
	
The name "DigitalFlipbook" must not be used to endorse or promote products
derived from the source code without prior written permission.
	
You agree to indemnify, hold harmless and defend DigitalFlipbook from and
against any loss, damage, claims or lawsuits, including attorney's
fees that arise or result from your use or distribution of the source
code.
	
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL DIGITALFLIPBOOK
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.digitalflipbook.webapis.scribd
{
	import com.adobe.webapis.URLLoaderBase;
	import com.digitalflipbook.webapis.scribd.scribdservice_internal;
	import com.digitalflipbook.webapis.scribd.methodgroups.*;
	
	import flash.net.URLLoader;
	
	/**
	 * Class that provides an ActionScript 3 API to the Scribd platform.
	 * 
	 * @see http://www.scribd.com/platform/
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 9.0
	 * @tiptext
	 *
 	 * @author Mark Walters, www.digitalflipbook.com
	 */
	public class ScribdService extends URLLoaderBase
	{
		/**
		 * The REST endpoint where we can talk with Scribd service
		 */
		public static const END_POINT:String = "http://api.scribd.com/api?";
		
		/**
		 * The endpoint where we go for authentication
		 */
		public static const AUTH_END_POINT:String = "http://api.scribd.com/api?";
		
		/** 
		 * Store the API key that gives developers access to the S service 
		 */
		private var _api_key:String;
		
		/** 
		 * Store the session key of the logged in user. 
		 */
		private var _session_key:String;

		/**
		 * The "shared secret" of your application for authentication
		 */
		private var _secret:String;
		
		/**
		 * Private variables that we provide read-only access to
		 */
		private var _docs:Docs;
		private var _user:User;
		
		public function ScribdService( api_key:String )
		{
			_api_key = api_key;
			
			_docs = new Docs( this );
			_user = new User( this );
		}
		
		/**
		 * Returns the current API key in use for accessing the Scribd service.
		 *  
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function get api_key():String
		{
			return _api_key;
		}
		
		/**
		 * Sets the API key that should be used to access the Scribd service.
		 *
		 * @param value The API key to use against Scribd.com
		 * @see http://www.scribd.com/platform/documentation/api?method_name=user.login
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function set api_key( value:String ):void
		{
			_api_key = value;
		}
		
		/**
		 * Returns the current session key of the logged in user.
		 *  
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function get session_key():String
		{
			return _session_key;	
		}
		
		/**
		 * Sets the session key for the logged in user.
		 *
		 * @param value The session key to use against Scribd.com
		 * @see http://www.scribd.com/platform/documentation/api?method_name=user.login
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function set session_key( value:String ):void
		{
			_session_key = value;	
		}

		/**
		 * Returns the "shared secret" of the Application associated with
		 * the API key for use in Authentication.
		 * 
		 * @see http://www.scribd.com/platform/documentation/api?method_name=user.login
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function get secret():String
		{
			return _secret;	
		}
		
		/**
		 * Sets the "shared secret" to that of an Application configured against
		 * the API key for use in Authentication.
		 *
		 * @param value The "shared secret" of the Application to authenticate 
		 *			against.
		 * @see http://www.scribd.com/platform/documentation/api?method_name=user.login
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function set secret( value:String ):void
		{
			_secret = value;	
		}
		
		/**
		 * Provide read-only access to the Docs method group in the Scribd API
		 *
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function get docs():Docs
		{
			return _docs;	
		}
		
		/**
		 * Provide read-only access to the User method group in the Scribd API
		 *
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function get user():User
		{
			return _user;	
		}

		/**
		 * Returns the URL to use for authentication so the developer
		 * doesn't have to build it by hand.
		 *
		 * @return The url to authenticate against
		 * @langversion ActionScript 3.0
		 * @playerversion Flash 9.0
		 * @tiptext
		 */
		public function getLoginURL():String
		{
			var auth_url:String = AUTH_END_POINT;
			auth_url += "api_key=" + api_key;
			
			return auth_url;
		}
		
		/**
		 * Use our "internal" namespace to provide access to the URLLoader
		 * from this class to the helper classes in the methodgroups package.
		 * This keeps this method away from the public API since it is not meant
		 * to be used by the public.
		 */
		scribdservice_internal function get urlLoader():URLLoader
		{
			return getURLLoader();	
		}
		
	}
	
}
